
import axios from "axios";
import PolylineTrailMaterialProperty from "../utils/PolylineTrailMaterialProperty";
const DataManagerScene = (function () {

    //添加图标
    function addBillboard(data, type) {
        var width = 30, height = 38;
        var imageurl = require("../assets/images/mark1.png");
        viewer.entities.add({
            // id: id,
            type: type,//自定义属性
            name: data.Name,
            show: true,
            position: Cesium.Cartesian3.fromDegrees(data.X, data.Y, 20),
            //orientation: new Cesium.VelocityOrientationProperty(property),
            billboard: {
                image: imageurl,  //改图片路径
                //eyeOffset: new Cesium.Cartesian3(0, 0, -10),
                width: width,
                height: height,
                scale: 1.0,
                scaleByDistance: new Cesium.NearFarScalar(1000, 1.0, 1200, 0.8),
                distanceDisplayCondition: new Cesium.DistanceDisplayCondition(1.0, 200000.0),
                verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
                horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
                show: true
            }
        });
    }

    //添加线
    function addPolyLine(id, name, type, positions, width, color) {
        viewer.entities.add({
            id: id,
            name: name,
            type: type,
            show: true,
            polyline: {
                positions: Cesium.Cartesian3.fromDegreesArray(positions), //[经度，纬度，经度，纬度...]
                // positions: Cesium.Cartesian3.fromDegreesArrayHeights(positions),
                width: width,
                material: Cesium.Color.fromCssColorString(color),
                distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0, 200000.0),
                clampToGround: true
                //arcType: Cesium.ArcType.GEODESIC
            },
        });
    }

    //添加多边形面
    function addPolygon(id, type, positions, color) {
        viewer.entities.add({
            id: id,
            type: type,
            show: true,
            polygon: {
                //heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
                hierarchy: Cesium.Cartesian3.fromDegreesArray(positions),
                material: Cesium.Color.fromCssColorString(color).withAlpha(0.5),
                distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0, 200000.0),
            }
        });
    }

    //添加多边形面带黑色边框线
    function addPolygonLine(id, type, positions, color) {
        viewer.entities.add({
            id: id,
            type: type,
            show: true,
            polygon: {
                //heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
                hierarchy: Cesium.Cartesian3.fromDegreesArray(positions),
                material: Cesium.Color.fromCssColorString(color).withAlpha(0.5),
                distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0, 200000.0),
            },
            polyline: {
                positions: Cesium.Cartesian3.fromDegreesArray(positions),
                width: 1,
                material: Cesium.Color.BLACK,
                distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0, 200000.0),
                clampToGround: true
            }
        });
    }

    //添加多边形面带黑色边框线并添加标签
    function addPolygonLineLabel(id, type, data, color, alpha) {
        var font = "18px Microsoft YaHei";
        // alpha = alpha | 0.5;
        viewer.entities.add({
            id: id,
            name: data.Name,
            type: type,
            show: true,
            polygon: {
                //heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
                hierarchy: Cesium.Cartesian3.fromDegreesArray(data.positions),
                material: Cesium.Color.fromCssColorString(color).withAlpha(alpha),
                distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0, 200000.0),
            },
            polyline: {
                positions: Cesium.Cartesian3.fromDegreesArray(data.positions),
                width: 1,
                material: Cesium.Color.BLACK,
                distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0, 200000.0),
                clampToGround: true
            },
            position: Cesium.Cartesian3.fromDegrees(data.centrepoint.X, data.centrepoint.Y, 10),
            label: {
                text: data.Name,
                font: font,
                fillColor: Cesium.Color.BLACK,
                verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
                // horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
                // horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
                distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0, 200000.0),
                show: true
            }
        });
        // viewer.zoomTo(viewer.entities);
        viewer.flyTo(viewer.entities);
    }
    //解析geojson数据
    function geojson(jsonData, dataType) {
        var data = [];
        var length = jsonData.features.length;
        if (dataType == "line") {//线
            for (var i = 0; i < length; i++) {
                var positions = [];
                var arr = jsonData.features[i].geometry.coordinates[0];
                for (var j = 0; j < arr.length; j++) {
                    arr[j].splice(2, 1);
                    positions = positions.concat(arr[j]);
                }
                data.push({ positions: positions });
            }
        } else if (dataType == "point") {//点
            for (var i = 0; i < length; i++) {
                data.push({
                    //Name: "",
                    X: jsonData.features[i].geometry.coordinates[0],
                    Y: jsonData.features[i].geometry.coordinates[1],
                    //Z: jsonData.features[0].geometry.coordinates[2]
                });
            }
        } else if (dataType == "polygon") {//带洞的面(画水面解析代码)
            for (var i = 0; i < length; i++) {
                let name = jsonData.features[i].properties.Name;
                var coordinatesLength =
                    jsonData.features[i].geometry.coordinates.length;
                let positions = [];
                for (var k = 0; k < coordinatesLength; k++) {
                    positions = [];
                    var arrcoordinates = jsonData.features[i].geometry.coordinates[k];
                    // if (arrcoordinates.length == 1) {
                    //   let arr = arrcoordinates[0];
                    //   for (let m = 0; m < arr.length; m++) {
                    //     arr[m].splice(2, 1);
                    //     positions = positions.concat(arr[m]);
                    //   }
                    // } else {
                    positions = [];
                    let holes = [];
                    for (var j = 0; j < arrcoordinates.length; j++) {
                        let arr = arrcoordinates[j];
                        holes = [];
                        for (let m = 0; m < arr.length; m++) {
                            arr[m].splice(2, 1);
                            holes = holes.concat(arr[m]);
                        }
                        positions.push(holes);
                    }
                    // }
                    data.push({
                        name: name,
                        positions: positions,
                        point: { X: positions[0][0], Y: positions[0][1] }
                    });
                }
            }
        }
        return data;
    }

    //解析arcgisjson数据
    function arcgisjson(jsonData, dataType) {
        var data = [];
        var length = jsonData.features.length;
        if (dataType == "点") {
            for (var i = 0; i < length; i++) {
                data.push({
                    Name: jsonData.features[i].attributes.NAME ? jsonData.features[i].attributes.NAME : jsonData.features[i].attributes.name,
                    bh: jsonData.features[i].attributes.bh,
                    num: jsonData.features[i].attributes.bh ? jsonData.features[i].attributes.bh.replace('K', '') : null,
                    ELEVATION: jsonData.features[i].attributes.ELEVATION,
                    MS: jsonData.features[i].attributes.MS,
                    X: jsonData.features[i].geometry.x,
                    Y: jsonData.features[i].geometry.y,
                    // Z: jsonData.features[i].attributes.MS
                });
            }
        } else if (dataType == "面") {
            for (var i = 0; i < length; i++) {
                var ringsLength = jsonData.features[i].geometry.rings.length;
                for (var k = 0; k < ringsLength; k++) {
                    var positions = [], position = [];
                    var X = 0, Y = 0;
                    var arr = jsonData.features[i].geometry.rings[k];
                    for (var j = 0; j < arr.length; j++) {
                        arr[j].splice(2, 1);
                        positions = positions.concat(arr[j]);
                        X += arr[j][0];
                        Y += arr[j][1];
                    }
                    position = { X: X / arr.length, Y: Y / arr.length }
                    data.push({
                        Name: jsonData.features[i].attributes.name ? jsonData.features[i].attributes.name : jsonData.features[i].attributes.名称,
                        // LX: jsonData.features[i].attributes.TDLX ? jsonData.features[i].attributes.TDLX : jsonData.features[i].attributes.LX,
                        positions: positions,
                        centrepoint: position
                    });
                }
            }
        } else if (dataType == "线") {
            for (var i = 0; i < length; i++) {
                var positions = [];
                var arr = jsonData.features[i].geometry.paths[0];
                let attributes = jsonData.features[i].attributes;
                for (var j = 0; j < arr.length; j++) {
                    arr[j].splice(2, 1);
                    positions = positions.concat(arr[j]);
                    // if (attributes.D_S) {
                    //     let high = random(0, 2);
                    //     positions.push(-high);
                    // }
                    if (attributes.MS) {
                        positions.push(-attributes.MS);
                    }
                }
                let radius, width, height;
                if (attributes.D_S) {
                    if (attributes.D_S.indexOf("DN") > -1) {
                        let strnum = attributes.D_S.replace("DN", "");
                        radius = strnum && strnum != "" ? Number(strnum) / 1000 / 2 : null;
                    } else if (attributes.D_S.indexOf("d") > -1) {
                        let strnum = attributes.D_S.replace("d", "");
                        radius = strnum && strnum != "" ? Number(strnum) / 1000 / 2 : null;
                    } else if (attributes.D_S.indexOf("X") > -1) {
                        let str = attributes.D_S.split("X");
                        width = str[0] ? Number(str[0]) / 1000 : null;
                        height = str[1] ? Number(str[1]) / 1000 : null;
                    } else if (attributes.D_S == " ") {
                        radius = 0.5;
                    } else {
                        radius = attributes.D_S ? Number(attributes.D_S) / 2 : null;
                        width = attributes.W ? attributes.W.toFixed(2) : null;
                        height = attributes.H ? attributes.H.toFixed(2) : null;
                    }
                }
                data.push({
                    // name: attributes.name,
                    // radius: attributes.D_S ? Number(attributes.D_S) / 2 : null,
                    // width: attributes.W ? attributes.W.toFixed(2) : null,
                    // height: attributes.H ? attributes.H.toFixed(2) : null,
                    radius: radius ? radius : null,
                    width: width ? width : null,
                    height: height ? height : null,
                    positions: positions
                });
            }
        }
        return data;
    }

    //根据类型查找Entity
    function findEntityByType(type) {
        var entitys = [];
        var entity = viewer.entities.values;
        if (entity.length > 0) {
            entitys = entity.filter(item => item.type === type);
        }
        return entitys;
    }

    //根据名称查找Primitive
    function findPrimitiveByName(name) {
        let primitives = [];
        var primitive = viewer.scene.primitives._primitives;
        if (primitive.length > 0) {
            primitives = primitive.filter(item => item.name === name);
        }
        return primitives;
        // let primitives = viewer.scene.primitives;
        // let length = primitives._primitives.length;
        // for (let i = length - 1; i >= 0; i--) {
        //     let p = primitives._primitives[i];
        //     if (p.name == name) {
        //         // p.show = !p.show;
        //         viewer.scene.primitives.remove(p);
        //     }
        // }
    }

    //异步根据数据加载点、线、面数据
    async function getWFS(data, type) {
        try {
            // if (data.wfsType == "面") {
            //     data.data = "http://119.3.43.73:6080/arcgis/rest/services/test0114/test114/MapServer/3/query?where=0%3D0&f=pjson";
            // }
            let res = await axios.get(data.data, {});
            let resData = res.data;
            if (resData) {
                let datas = arcgisjson(resData, data.wfsType);
                //无人机巡检
                if (data.data.indexOf("WRJXJD/MapServer/1") > -1) {//里程桩
                    patrolUAV.handleForDatas(data, datas);
                }
                for (let i = 0; i < datas.length; i++) {
                    if (type == "pipe") {
                        pipe.handleForData(data, datas[i]);
                    } else if (type == "vim") {
                        vim.handleForData(data, datas[i]);
                    } else if (type == "patrolUAV") {
                        patrolUAV.handleForData(data, datas[i]);
                    } else {
                        if (data.wfsType == "点") {
                            // if (type == "pipe") {
                            //     let imageurl = require("../assets/images/icon_well.png");
                            //     if (data.data.indexOf("MapServer/2") > -1) {
                            //         imageurl = require("../assets/images/icon_well2.png");
                            //     } else if (data.data.indexOf("MapServer/3") > -1) {
                            //         imageurl = require("../assets/images/icon_well3.png");
                            //     } else if (data.data.indexOf("MapServer/4") > -1) {
                            //         imageurl = require("../assets/images/icon_well4.png");
                            //     }
                            //     pipe.addCylinder(datas[i], data.id, 1, imageurl);
                            // } else {
                            addBillboard(datas[i], data.id);
                            // }
                        } else if (data.wfsType == "线") {
                            // if (type == "pipe") {
                            //     let color = "";
                            //     if (data.data.indexOf("MapServer/5") > -1) {
                            //         color = "#0070ff";
                            //     } else if (data.data.indexOf("MapServer/6") > -1) {
                            //         color = "#a8a800";
                            //     } else if (data.data.indexOf("MapServer/7") > -1) {
                            //         color = "#a900e6";
                            //     } else if (data.data.indexOf("MapServer/8") > -1) {
                            //         color = "#d1ff73";
                            //     } else if (data.data.indexOf("MapServer/9") > -1) {
                            //         color = "#ffa77f";
                            //     }
                            //     pipe.addPolylineVolumeLine(data.name, data.id, datas[i], 2, color);
                            //     // pipe.addPolylineVolumeCircleLine(data.name, data.id, datas[i].positions, 1, 2, color);
                            // } else {
                            addPolyLine(null, data.name, data.id, datas[i].positions, 2, "yellow");
                            // }
                        } else if (data.wfsType == "面") {
                            addPolygon(null, data.id, datas[i].positions, "#ffffff");
                        }

                    }
                }
            }
        } catch (e) {
            console.log(e);
        }
    }

    //加载矢量WFS
    function handleForWFS(data, type) {
        let entitys = findEntityByType(data.id);
        let primitives = findPrimitiveByName(data.id);
        if (entitys.length > 0) {
            entitys.filter(item => item.show = data.checked);
        } else if (primitives.length > 0) {
            primitives.filter(item => item.show = data.checked);
        } else {
            if (data.checked) {
                getWFS(data, type);
            }
        }
    }
    function random(min, max) {
        return Math.round((Math.random() * (max - min) + min) * 100) / 100;
    }

    //山体滑坡数据
    function handleForSTHPData(data, type) {
        //所有的监控点
        var dataBZ = [
            { NO: 1, BZLX: '摄像头', Name: '摄像监控一号位', X: '115.130803', Y: '30.199585', Z: '61.25742' },
            { NO: 2, BZLX: '摄像头', Name: '摄像监控二号位', X: '115.129435', Y: '30.198922', Z: '79.25742' },
            { NO: 3, BZLX: '摄像头', Name: '摄像监控三号位', X: '115.131389', Y: '30.199984', Z: '60.25742' },
            { NO: 4, BZLX: '摄像头', Name: '摄像监控四号位', X: '115.130571', Y: '30.200369', Z: '45.25742' },
            { NO: 5, BZLX: '摄像头', Name: '摄像监控五号位', X: '115.129881', Y: '30.199916', Z: '61.25742' },
            { NO: 6, BZLX: '摄像头', Name: '摄像监控六号位', X: '115.131241', Y: '30.199261', Z: '85.25742' },
            { NO: 7, BZLX: '水量监控', Name: '水量监控一号位', X: '115.13083', Y: '30.198295', Z: '104.25742' },
            { NO: 8, BZLX: '水量监控', Name: '水量监控二号位', X: '115.129551', Y: '30.199271', Z: '68.25742' },
            { NO: 9, BZLX: '水量监控', Name: '水量监控三号位', X: '115.129988', Y: '30.199257', Z: '65.25742' },
            { NO: 10, BZLX: '水量监控', Name: '水量监控四号位', X: '115.130252', Y: '30.199413', Z: '55.25742' },
            { NO: 11, BZLX: '水量监控', Name: '水量监控五号位', X: '115.132004', Y: '30.199257', Z: '90.25742' },
            { NO: 12, BZLX: '水量监控', Name: '水量监控六号位', X: '115.132004', Y: '30.200957', Z: '45.25742' },
            { NO: 13, BZLX: '水量监控', Name: '水量监控七号位', X: '115.129875', Y: '30.201204', Z: '60.25742' },
            { NO: 14, BZLX: '压力监控', Name: '压力监控一号位', X: '115.130578', Y: '30.198834', Z: '86.25742' },
            { NO: 15, BZLX: '压力监控', Name: '压力监控二号位', X: '115.12921', Y: '30.197733', Z: '100.25742' },
            { NO: 16, BZLX: '压力监控', Name: '压力监控三号位', X: '115.129623', Y: '30.199878', Z: '64.25742' },
            { NO: 17, BZLX: '压力监控', Name: '压力监控四号位', X: '115.133926', Y: '30.199157', Z: '70.25742' },
            { NO: 18, BZLX: '压力监控', Name: '压力监控五号位', X: '115.133226', Y: '30.199157', Z: '80.25742' },
            { NO: 19, BZLX: '压力监控', Name: '压力监控六号位', X: '115.132726', Y: '30.199101', Z: '92.25742' },
            { NO: 20, BZLX: '压力监控', Name: '压力监控七号位', X: '115.129815', Y: '30.201664', Z: '55.25742' },
            { NO: 21, BZLX: '压力监控', Name: '压力监控八号位', X: '115.13131', Y: '30.200868', Z: '39.25742' },
            { NO: 22, BZLX: '压力监控', Name: '压力监控九号位', X: '115.129147', Y: '30.200954', Z: '65.25742' },
            { NO: 23, BZLX: '压力监控', Name: '压力监控十号位', X: '115.130782', Y: '30.201453', Z: '43.25742' }
        ];
        //闪烁预警的点
        var pointDatas = [
            { NO: 14, BZLX: '压力监控', Name: '压力监控一号位', X: '115.130578', Y: '30.198834', Z: '84.25742' },
            { NO: 19, BZLX: '压力监控', Name: '压力监控六号位', X: '115.132726', Y: '30.199101', Z: '91.25742' },
            { NO: 15, BZLX: '压力监控', Name: '压力监控二号位', X: '115.12921', Y: '30.197733', Z: '96.25742' }
        ];
        for (var i = 0; i < dataBZ.length; i++) {
            sthp.addBillboardPump(dataBZ[i], i);
        }
        sthp.showAt(dataBZ);
        for (var i = 0; i < pointDatas.length; i++) {
            sthp.twinklePoint(pointDatas[i]);
        }
    }

    // 地图弹框
    var TooltipDiv = (function () {

        var isInit = false;

        function _() { };

        _.initTool = function (frameDiv) {
            if (isInit) { return; }

            var div = document.createElement('DIV');
            div.className = "toolTip-left";//tooltipdiv right   toolTip-left

            //var arrow = document.createElement('DIV');
            //arrow.className = "tooltipdiv-arrow";
            //div.appendChild(arrow);

            var title = document.createElement('DIV');
            title.className = "tooltipdiv-inner";
            div.appendChild(title);

            this._div = div;
            this._title = title;

            frameDiv.appendChild(div);

            isInit = true;
        }

        _.setVisible = function (visible) {
            if (!isInit) { return; }
            this._div.style.display = visible ? 'block' : 'none';
        };

        /*
        position屏幕坐标
        显示在屏幕上
        */
        _.showAt = function (position, message) {
            if (!isInit) { return; }
            if (position && message) {
                this.setVisible(true);
                this._title.innerHTML = message;
                this._div.style.position = "absolute"
                this._div.style.left = position.x + 30 + "px";
                this._div.style.top = (position.y - this._div.clientHeight / 2) + "px";
            }
        };

        return _;
    })();


    /**
     * 管网场景
     */
    const pipe = {
        //添加图标
        addBillboard(data, type, imageurl) {
            //var width = 30, height = 38;
            var width = 30, height = 30;
            // var imageurl = data.imgurl;
            viewer.entities.add({
                // id: id,
                type: type,//自定义属性
                name: data.Name,
                show: true,
                position: Cesium.Cartesian3.fromDegrees(data.X, data.Y, 20),
                //orientation: new Cesium.VelocityOrientationProperty(property),
                billboard: {
                    image: imageurl,  //改图片路径
                    //eyeOffset: new Cesium.Cartesian3(0, 0, -10),
                    width: width,
                    height: height,
                    scale: 1.0,
                    scaleByDistance: new Cesium.NearFarScalar(1000, 1.0, 1200, 0.8),
                    distanceDisplayCondition: new Cesium.DistanceDisplayCondition(1.0, 200000.0),
                    verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
                    horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
                    show: true
                }
            });
        },

        //添加圆柱体管点
        addCylinder(data, type, radius, image) {
            viewer.entities.add({
                // id: id,
                name: data.Name,
                type: type,//自定义属性
                position: Cesium.Cartesian3.fromDegrees(data.X, data.Y, -(data.MS / 2 - 0.3)),//(radius * 1.1)
                cylinder: {
                    length: data.MS + 0.5,//radius * 2.1
                    topRadius: radius,
                    bottomRadius: radius,
                    material: new Cesium.ImageMaterialProperty({
                        image: image,
                        repeat: new Cesium.Cartesian2(1.0, 1.0),
                    }),
                    distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0, 500.0),
                    // outline: true,
                    // outlineColor: Cesium.Color.DARK_GREEN,
                },
            });
        },

        //添加圆形管道带线
        addPolylineVolumeCircleLine: function (name, type, positions, radius, width, color) {
            let material = new Cesium.PolylineTrailMaterialProperty({
                //创建材质
                color: Cesium.Color.fromCssColorString(color), //Cesium.Color.RED.withAlpha(0.5),
                duration: 6000, //3000
                ratio: 2.0,
                trailImage: require("../assets/images/lineClr.png")
            });
            viewer.entities.add({
                name: name,
                type: type,
                show: true,
                polylineVolume: {
                    positions: Cesium.Cartesian3.fromDegreesArray(positions),//[经度，纬度，经度，纬度...]
                    // positions: Cesium.Cartesian3.fromDegreesArrayHeights(positions),//[经度，纬度，高度，经度，纬度，高度...]
                    shape: pipe.computeCircle(radius),
                    // material: Cesium.Color.RED,
                    material: Cesium.Color.fromCssColorString(color),
                    distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0, 500.0),
                },
                polyline: {
                    positions: Cesium.Cartesian3.fromDegreesArray(positions),//[经度，纬度，经度，纬度...]
                    // positions: Cesium.Cartesian3.fromDegreesArrayHeights(positions),
                    width: width,
                    material: material,
                    distanceDisplayCondition: new Cesium.DistanceDisplayCondition(500.0, 200000.0),
                    clampToGround: true
                    //arcType: Cesium.ArcType.GEODESIC
                },
            });
        },
        //添加管道带线
        addPolylineVolumeLine: function (name, type, data, width, color) {
            let positions = data.positions;
            let shape = null;
            if (data.radius) {
                shape = pipe.computeCircle(data.radius);
            } else if (data.width && data.height) {
                shape = pipe.computeSquare(data.width, data.height)
            } else {
                shape = pipe.computeCircle(0.5);
            }

            let material = new Cesium.PolylineTrailMaterialProperty({
                //创建材质
                color: Cesium.Color.fromCssColorString(color), //Cesium.Color.RED.withAlpha(0.5),
                duration: 6000, //3000
                ratio: 2.0,
                trailImage: require("../assets/images/lineClr.png")
            });
            viewer.entities.add({
                name: name,
                type: type,
                show: true,
                polylineVolume: {
                    // positions: Cesium.Cartesian3.fromDegreesArray(positions),//[经度，纬度，经度，纬度...]
                    positions: Cesium.Cartesian3.fromDegreesArrayHeights(positions),//[经度，纬度，高度，经度，纬度，高度...]
                    shape: shape,
                    // material: Cesium.Color.RED,
                    material: Cesium.Color.fromCssColorString(color),
                    distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0, 500.0),
                },
                polyline: {
                    // positions: Cesium.Cartesian3.fromDegreesArray(positions),//[经度，纬度，经度，纬度...]
                    positions: Cesium.Cartesian3.fromDegreesArrayHeights(positions),
                    width: width,
                    material: material,
                    distanceDisplayCondition: new Cesium.DistanceDisplayCondition(500.0, 200000.0),
                    // clampToGround: true
                    //arcType: Cesium.ArcType.GEODESIC
                },
            });
        },

        //管道形状【方】
        computeSquare(width, height) {
            return [
                new Cesium.Cartesian2(-(width / 2), -(height / 2)),
                new Cesium.Cartesian2(width / 2, -(height / 2)),
                new Cesium.Cartesian2(width / 2, height / 2),
                new Cesium.Cartesian2(-(width / 2), (height / 2)),
            ];
        },
        // //管道形状【方】 radius整个管道的外半径
        // computeSquare(radius) {
        //     return [
        //         new Cesium.Cartesian2(-radius, -radius),
        //         new Cesium.Cartesian2(radius, -radius),
        //         new Cesium.Cartesian2(radius, radius),
        //         new Cesium.Cartesian2(-radius, radius)
        //     ];
        // },
        //管道形状【内空管道】 radius整个管道的外半径
        computeKxCircle(radius) {
            var hd = radius / 3;
            var startAngle = 0;
            var endAngle = 360;

            var pss = [];
            for (var i = startAngle; i <= endAngle; i++) {
                var radians = Cesium.Math.toRadians(i);
                pss.push(
                    new Cesium.Cartesian2(
                        radius * Math.cos(radians),
                        radius * Math.sin(radians)
                    )
                );
            }
            for (var i = endAngle; i >= startAngle; i--) {
                var radians = Cesium.Math.toRadians(i);
                pss.push(
                    new Cesium.Cartesian2(
                        (radius - hd) * Math.cos(radians),
                        (radius - hd) * Math.sin(radians)
                    )
                );
            }
            return pss;
        },
        //管道形状【圆柱体】 radius整个管道的外半径
        computeCircle(radius) {
            var positions = [];
            for (var i = 0; i < 360; i++) {
                var radians = Cesium.Math.toRadians(i);
                positions.push(
                    new Cesium.Cartesian2(
                        radius * Math.cos(radians),
                        radius * Math.sin(radians)
                    )
                );
            }
            return positions;
        },
        //管道形状【星状】 radius整个管道的外半径 ,arms星角的个数
        computeStar(arms, rOuter, rInner) {
            var angle = Math.PI / arms;
            var length = 2 * arms;
            var positions = new Array(length);
            for (var i = 0; i < length; i++) {
                var r = i % 2 === 0 ? rOuter : rInner;
                positions[i] = new Cesium.Cartesian2(
                    Math.cos(i * angle) * r,
                    Math.sin(i * angle) * r
                );
            }
            return positions;
        },
        //三角形
        computeTriangle(radius) {
            var jiaodu = 60;
            var hudu = Cesium.Math.toRadians(jiaodu);
            var positions = [];
            positions.push(new Cesium.Cartesian2(-radius * Math.cos(hudu), -radius * Math.sin(hudu) / 2));
            positions.push(new Cesium.Cartesian2(radius * Math.cos(hudu), -radius * Math.sin(hudu) / 2));
            positions.push(new Cesium.Cartesian2(0, radius * Math.sin(hudu) / 2));
            return positions;
        },
        /**
         * 执行数据
         * @param {*} data 数据源(带wfs链接Url)
         * @param {*} jsonData 根据WFS数据获取arcgisjson数据
         */
        handleForData(data, jsonData) {
            if (data.wfsType == "点") {
                let imageurl = require("../assets/images/icon_well.png");
                if (data.data.indexOf("MapServer/2") > -1) {
                    imageurl = require("../assets/images/icon_well2.png");
                } else if (data.data.indexOf("MapServer/3") > -1) {
                    imageurl = require("../assets/images/icon_well3.png");
                } else if (data.data.indexOf("MapServer/4") > -1) {
                    imageurl = require("../assets/images/icon_well4.png");
                }
                pipe.addCylinder(jsonData, data.id, 0.5, imageurl);
            } else if (data.wfsType == "线") {
                let color = "";
                if (data.data.indexOf("MapServer/5") > -1) {
                    color = "#0070ff";
                } else if (data.data.indexOf("MapServer/6") > -1) {
                    color = "#a8a800";
                } else if (data.data.indexOf("MapServer/7") > -1) {
                    color = "#a900e6";
                } else if (data.data.indexOf("MapServer/8") > -1) {
                    color = "#d1ff73";
                } else if (data.data.indexOf("MapServer/9") > -1) {
                    color = "#ffa77f";
                }
                pipe.addPolylineVolumeLine(data.name, data.id, jsonData, 2, color);
                // pipe.addPolylineVolumeCircleLine(data.name, data.id, datas[i].positions, 1, 2, color);
            }
        }
    }

    /**
     * 农村VIM场景
     */
    const vim = {

        //添加图标
        addBillboard(data, type, imageurl) {
            //var width = 30, height = 38;
            var width = 32, height = 80;
            // var imageurl = data.imgurl;
            viewer.entities.add({
                // id: id,
                type: type,//自定义属性
                name: data.Name,
                show: true,
                position: Cesium.Cartesian3.fromDegrees(data.X, data.Y, 20),
                //orientation: new Cesium.VelocityOrientationProperty(property),
                billboard: {
                    image: imageurl,  //改图片路径
                    //eyeOffset: new Cesium.Cartesian3(0, 0, -10),
                    width: width,
                    height: height,
                    scale: 1.0,
                    scaleByDistance: new Cesium.NearFarScalar(1000, 1.0, 1200, 0.8),
                    distanceDisplayCondition: new Cesium.DistanceDisplayCondition(1.0, 200000.0),
                    verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
                    horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
                    show: true
                }
            });
        },
        addPolyLine(id, name, type, positions, width, color) {
            let material = new Cesium.PolylineTrailMaterialProperty({
                //创建材质
                color: Cesium.Color.fromCssColorString(color), //Cesium.Color.RED.withAlpha(0.5),
                duration: 3000, //3000
                ratio: 2.0,
                trailImage: require("../assets/images/lineClr.png")
            });
            viewer.entities.add({
                id: id,
                name: name,
                type: type,
                show: true,
                polyline: {
                    positions: Cesium.Cartesian3.fromDegreesArray(positions), //[经度，纬度，经度，纬度...]
                    // positions: Cesium.Cartesian3.fromDegreesArrayHeights(positions),
                    width: width,
                    material: material,
                    distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0, 200000.0),
                    clampToGround: true
                    //arcType: Cesium.ArcType.GEODESIC
                },
            });
        },

        //添加多边形面
        addPolygon(id, name, type, positions, color) {
            viewer.entities.add({
                id: id,
                name: name,
                type: type,
                show: true,
                polygon: {
                    //heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
                    hierarchy: Cesium.Cartesian3.fromDegreesArray(positions),
                    material: Cesium.Color.fromCssColorString(color).withAlpha(0.5),
                    distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0, 200000.0),
                }
            });
        },
        //添加多边形面带黑色边框线
        addPolygonLine: function (id, name, type, positions, color) {
            viewer.entities.add({
                id: id,
                name: name,
                type: type,
                show: true,
                polygon: {
                    //heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
                    hierarchy: Cesium.Cartesian3.fromDegreesArray(positions),
                    material: Cesium.Color.fromCssColorString(color).withAlpha(0.5),
                    distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0, 200000.0),
                },
                polyline: {
                    positions: Cesium.Cartesian3.fromDegreesArray(positions),
                    width: 1,
                    material: Cesium.Color.fromCssColorString("#6e6e6e"),
                    distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0, 200000.0),
                    clampToGround: true
                }
            });
        },
        //添加边界墙
        addBoundary(name, type, positions, color) {
            var height = 60;
            // var positions = [];
            var minimumHeights = [];
            var maximumHeights = [];
            for (var i = 0, len = positions.length / 2; i < len; i++) {
                maximumHeights.push(height);
                minimumHeights.push(0);
            }
            //动态立体墙
            let material = mars3d.MaterialUtil.createMaterialProperty(mars3d.MaterialType.LineFlow, {
                image: require("../assets/images/fence.png"),
                color: Cesium.Color.fromCssColorString(color),
                speed: 10,
                axisY: true
            })
            // let material = new mars3d.LineFlowMaterial({//动画线材质
            //     color: Cesium.Color.fromCssColorString(color),
            //     duration: 2000, //时长，控制速度
            //     url: require("../assets/images/fence.png"),
            //     axisY: true
            // })
            // let material = new mars3d.LineFlowMaterial({
            //     //动画线材质
            //     color: Cesium.Color.fromCssColorString(color),
            //     duration: 3000, //时长，控制速度
            //     url: require("../assets/images/fence.png"),
            //     repeat: new Cesium.Cartesian2(5, 1),
            //     axisY: false
            // });
            // let material = new Cesium.PolylineTrailMaterialProperty({
            //     //创建材质
            //     color: Cesium.Color.fromCssColorString(color), //Cesium.Color.RED.withAlpha(0.5),
            //     duration: 9000, //3000
            //     ratio: 5.0,
            //     trailImage: require("../assets/images/fence.png")
            // });

            viewer.entities.add({
                name: name,
                type: type,
                wall: {
                    positions: Cesium.Cartesian3.fromDegreesArray(positions),
                    maximumHeights: maximumHeights,
                    minimumHeights: minimumHeights,
                    material: material,
                },
            });
        },
        //添加水面
        addWater(name, positions) {
            // let polygonHierarchy = new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArray(positions));
            // //水效果
            // var polygon = new Cesium.PolygonGeometry({
            //     height: 1, //水面高
            //     perPositionHeight: true,
            //     extrudedHeight: 1, //底部高
            //     polygonHierarchy: polygonHierarchy
            //     // material: Cesium.Color.withAlpha(0.5)
            // });
            // var primitive = mars3d.water.createWaterPrimitive(polygon, {
            //     normalMap: require("../assets/waterNormals.jpg"), //'./img/textures/waterNormals.jpg', //水正常扰动的法线图
            //     frequency: 9000.0, //控制波数的数字。
            //     animationSpeed: 0.03, //控制水的动画速度的数字。
            //     amplitude: 5.0, //控制水波振幅的数字。
            //     specularIntensity: 0.2, //控制镜面反射强度的数字。
            //     baseWaterColor: "#006ab4", //rgba颜色对象基础颜色的水。#00ffff,#00baff,#006ab4
            //     blendColor: "#006ab4", //从水中混合到非水域时使用的rgba颜色对象。
            //     clampToGround: false //是否贴地
            // });
            // primitive.name = name;
            // viewer.scene.primitives.add(primitive);

            // //创建Graphic图层
            // let graphicLayer = new mars3d.layer.GraphicLayer();
            // viewer.addLayer(graphicLayer);
            // positions = this.setPositionsHeight(positions);
            // let primitive = new mars3d.graphic.Water({
            //     // name: name,
            //     positions: positions,
            //     style: {
            //         height: 1, // 水面高度
            //         normalMap: require("../assets/waterNormals.jpg"), // 水正常扰动的法线图
            //         frequency: 8000.0, // 控制波数的数字。
            //         animationSpeed: 0.02, // 控制水的动画速度的数字。
            //         amplitude: 5.0, // 控制水波振幅的数字。
            //         specularIntensity: 0.8, // 控制镜面反射强度的数字。
            //         baseWaterColor: "#006ab4", // rgba颜色对象基础颜色的水。#00ffff,#00baff,#006ab4
            //         blendColor: "#006ab4", // 从水中混合到非水域时使用的rgba颜色对象。
            //         opacity: 0.7, // 透明度
            //         clampToGround: false, // 是否贴地
            //     },
            // });
            // graphicLayer.addGraphic(primitive);

            //cesium源
            let primitive = viewer.scene.primitives.add(
                new Cesium.Primitive({
                    geometryInstances: new Cesium.GeometryInstance({
                        geometry: new Cesium.PolygonGeometry({
                            polygonHierarchy: new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArray(positions)),
                            height: 1
                        }),
                    }),
                    appearance: new Cesium.EllipsoidSurfaceAppearance({
                        aboveGround: false,
                    }),
                    show: true,
                })
            );
            primitive.appearance.material = new Cesium.Material({
                fabric: {
                    type: "Water",
                    uniforms: {
                        // specularMap: "../images/earthspec1k.jpg",
                        // normalMap: Cesium.buildModuleUrl(
                        //     "Assets/Textures/waterNormals.jpg"
                        // ),
                        normalMap: require("../assets/waterNormals.jpg"),
                        frequency: 10000.0,
                        animationSpeed: 0.01,
                        amplitude: 5.0,
                    },
                },
            });
            primitive.name = name;
        },
        //设置位置高
        setPositionsHeight(positions, height) {
            let res = [];
            for (let i = 0; i < positions.length;) {
                if (height) {
                    res.push([Number(positions[i]), Number(positions[i + 1]), Number(height)]);
                } else {
                    res.push([Number(positions[i]), Number(positions[i + 1])]);
                }
                i = i + 2;
            }
            return res;
        },

        //cesium加载倾斜模型
        load3DTiles(data) {
            let translation = null;
            if (data.offsetHeight || data.offsetEast || data.offsetNorth) {
                translation = new Cesium.Cartesian3(
                    Number(data.offsetEast),
                    Number(data.offsetNorth),
                    Number(data.offsetHeight)
                );
            }
            let tileSet = new Cesium.Cesium3DTileset({
                show: true,
                name: data.name,
                url: data.url,
                // backFaceCulling: true,
                maximumScreenSpaceError: 1,
                maximumMemoryUsage: 1024,
                shadows: Cesium.ShadowMode.ENABLED, //ENABLED,DISABLED
                // cullWithChildrenBounds: true,
                // distanceDisplayCondition: new Cesium.DistanceDisplayCondition(
                //   0.0,
                //   50000.0
                // ), // 按照2021-8-30 新增
                // maximumNumberOfLoadedTiles: 300000,
            });

            // translation：Cesium.Cartesian3类型，里头就是x、y、z三个偏移量，分别代表朝东、朝北、朝天三个移动量，单位是米，允许为小数、负数
            // 偏移
            if (translation) {
                tileSet.readyPromise.then((tileSet) => {
                    // 在加载成功之后，需要获取这个图层的中心点的经纬度
                    // 1. 获取图层中心点的经纬度坐标和笛卡尔坐标
                    var boundingSphere = tileSet.boundingSphere;
                    var layerCoordinate = Cesium.Cartographic.fromCartesian(
                        boundingSphere.center
                    ); // 获取到图层中心点的经纬度坐标（弧度）
                    var layerSurfacePos = Cesium.Cartesian3.fromRadians(
                        layerCoordinate.longitude,
                        layerCoordinate.latitude,
                        0.0
                    ); //图层中心点所在的经纬度处的笛卡尔坐标

                    // 计算中心点所处位置的朝天向量
                    var ptUpPos = Cesium.Cartesian3.fromRadians(
                        layerCoordinate.longitude,
                        layerCoordinate.latitude,
                        10.0
                    );
                    var vecUp1 = Cesium.Cartesian3.subtract(
                        ptUpPos,
                        layerSurfacePos,
                        new Cesium.Cartesian3()
                    );
                    var vecUp = Cesium.Cartesian3.normalize(
                        vecUp1,
                        new Cesium.Cartesian3()
                    ); // 朝天向量
                    var vecUp_trans = new Cesium.Cartesian3(
                        vecUp.x * translation.z,
                        vecUp.y * translation.z,
                        vecUp.z * translation.z
                    ); // 朝天移动量

                    // 计算中心点所处位置的东向量
                    var ptEastPos = Cesium.Cartesian3.fromRadians(
                        layerCoordinate.longitude + 0.001,
                        layerCoordinate.latitude,
                        0.0
                    );
                    var vecEast1 = Cesium.Cartesian3.subtract(
                        ptEastPos,
                        layerSurfacePos,
                        new Cesium.Cartesian3()
                    );
                    var vecEast = Cesium.Cartesian3.normalize(
                        vecEast1,
                        new Cesium.Cartesian3()
                    ); // 朝东向量
                    var vecEast_trans = new Cesium.Cartesian3(
                        vecEast.x * translation.x,
                        vecEast.y * translation.x,
                        vecEast.z * translation.x
                    ); // 朝东移动量

                    // 计算中心点所处位置的北向量
                    var ptNorthPos = Cesium.Cartesian3.fromRadians(
                        layerCoordinate.longitude,
                        layerCoordinate.latitude + 0.001,
                        0.0
                    );
                    var vecNorth1 = Cesium.Cartesian3.subtract(
                        ptNorthPos,
                        layerSurfacePos,
                        new Cesium.Cartesian3()
                    );
                    var vecNorth = Cesium.Cartesian3.normalize(
                        vecNorth1,
                        new Cesium.Cartesian3()
                    ); // 朝北向量
                    var vecNorth_trans = new Cesium.Cartesian3(
                        vecNorth.x * translation.y,
                        vecNorth.y * translation.y,
                        vecNorth.z * translation.y
                    ); // 朝北移动量

                    // 朝天、朝东、朝北三个移动量加起来，就是整体偏移
                    var offset = new Cesium.Cartesian3(
                        vecUp_trans.x + vecEast_trans.x + vecNorth_trans.x,
                        vecUp_trans.y + vecEast_trans.y + vecNorth_trans.y,
                        vecUp_trans.z + vecEast_trans.z + vecNorth_trans.z
                    );

                    tileSet.modelMatrix = Cesium.Matrix4.fromTranslation(offset);
                });
            }
            viewer.scene.primitives.add(tileSet);
        },

        typeIds: [],
        /**
         * 执行数据
         * @param {*} data 数据源(带wfs链接Url)
         * @param {*} jsonData 根据WFS数据获取arcgisjson数据
         */
        handleForData(data, jsonData) {
            if (data.wfsType == "点") {
                let imageurl = require("../assets/images/gxcyd.png");
                // if (data.data.indexOf("GXCYBJ1126/MapServer/0") > -1) { //产业布局
                if (data.data.indexOf("GX/GXCJ/MapServer/0") > -1) { //广西产业点
                    imageurl = require("../assets/images/gxcyd.png");
                }
                this.addBillboard(jsonData, data.id, imageurl);
                if (this.typeIds.indexOf(data.id) < 0) {
                    this.typeIds.push(data.id);
                }
            } else if (data.wfsType == "线") {
                let color = "";
                // if (data.data.indexOf("gxghdk/MapServer/0") > -1) {//电力线
                if (data.data.indexOf("GX/GXCJ/MapServer/3") > -1) {//电力线
                    color = "#ffff00";
                    this.addPolyLine(null, data.name, data.id, jsonData.positions, 2, color);
                // } else if (data.data.indexOf("gxghdk/MapServer/1") > -1) {//村路线
                } else if (data.data.indexOf("GX/GXCJ/MapServer/5") > -1) {//村路线
                    color = "#4ce600";
                    this.addPolyLine(null, data.name, data.id, jsonData.positions, 2, color);
                // } else if (data.data.indexOf("GXCYBJ1126/MapServer/1") > -1) {//产业布局
                } else if (data.data.indexOf("GX/GXCJ/MapServer/4") > -1) {//村界线
                    color = "#ff0000";
                    this.addBoundary(data.name, data.id, jsonData.positions, color);
                }
            } else if (data.wfsType == "面") {
                var color = "";
                // if (data.data.indexOf("gxghdk/MapServer/2") > -1) {//土地改造
                if (data.data.indexOf("GX/GXCJ/MapServer/7") > -1) {//土地改造
                    if (jsonData.Name == "住宅用地") {
                        color = "#fcb6b7";
                    } else if (jsonData.Name == "新型农田整改") {
                        color = "#97dbf2";
                    } else if (jsonData.Name == "经济作物示范区") {
                        color = "#73b273";
                    }
                // } else if (data.data.indexOf("gxghdk/MapServer/3") > -1) {//土地规划
                } else if (data.data.indexOf("GX/GXCJ/MapServer/8") > -1) {//土地规划
                    if (jsonData.Name == "中学" || jsonData.Name == "小学" || jsonData.Name == "幼儿园") {
                        color = "#ffffbe";
                    } else if (jsonData.Name == "书店") {
                        color = "#e69800";
                    } else if (jsonData.Name == "休闲广场") {
                        color = "#ffbee8";
                    } else if (jsonData.Name == "便利店") {
                        color = "#fcd4ef";
                    } else if (jsonData.Name == "停车场") {
                        color = "#9c9c9c";
                    } else if (jsonData.Name == "公共服务" || jsonData.Name == "社区服务") {
                        color = "#ffebbe";
                    } else if (jsonData.Name == "公园") {
                        color = "#dffcd4";
                    } else if (jsonData.Name == "养老院") {
                        color = "#a80084";
                    } else if (jsonData.Name == "医院") {
                        color = "#7af5ca";
                    } else if (jsonData.Name == "发展大道" || jsonData.Name.substr(jsonData.Name.length - 1, 1) == "路") {//"新生路","规划一路","规划二路","规划三路","规划四路","规划道路"
                        color = "#f5f57a";
                    } else if (jsonData.Name == "垃圾处理站") {
                        color = "#fcc5f7";
                    } else if (jsonData.Name == "城市广场") {
                        color = "#ffbee8";
                    } else if (jsonData.Name == "政府") {
                        color = "#ff0000";
                    } else if (jsonData.Name == "百货商场") {
                        color = "#fcb3cf";
                    } else if (jsonData.Name == "绿化") {
                        color = "#38a800";
                    } else if (jsonData.Name == "超市") {
                        color = "#bdc6fc";
                    }
                // } else if (data.data.indexOf("gxghdk/MapServer/4") > -1) {//水面
                } else if (data.data.indexOf("GX/GXCJ/MapServer/6") > -1) {//水面
                    color = "#0070ff";
                    this.addWater(data.id, jsonData.positions);
                // } else if (data.data.indexOf("GXCYBJ1126/MapServer/2") > -1) {//产业布局
                } else if (data.data.indexOf("GX/GXCJ/MapServer/10") > -1) {//产业布局
                    if (jsonData.Name == "科技农业观光区体验区") {
                        color = "#c2dbfc";
                    } else if (jsonData.Name == "生态农业观光区体验区") {
                        color = "#fcb3f5";
                    } else if (jsonData.Name == "集体产业用地") {
                        color = "#b8fcf7";
                    } else if (jsonData.Name == "民宿体验区") {
                        color = "#f7d7fc";
                    } else {
                        color = "#cde9f7";
                    }

                } else if (data.data.indexOf("GX/GXCJ/MapServer/9") > -1) {//生态休闲
                    if (jsonData.Name == "农业休闲观光区") {
                        color = "#fcbebd";
                    } else if (jsonData.Name == "创意文化传统村落") {
                        color = "#bdb3fc";
                    } else if (jsonData.Name == "生态景观区") {
                        color = "#f7d7fc";
                    } else if (jsonData.Name == "美丽乡村体验区") {
                        color = "#e8fcd2";
                    } else {
                        color = "#cde9f7";
                    }
                }
                // if (data.data.indexOf("gxghdk/MapServer/4") < 0) {
                if (data.data.indexOf("GX/GXCJ/MapServer/6") < 0) {
                    this.addPolygonLine(null, jsonData.Name, data.id, jsonData.positions, color);
                    if (this.typeIds.indexOf(data.id) < 0) {
                        this.typeIds.push(data.id);
                    }
                }
                // this.addPolygon(null, data.name, data.id, jsonData.positions, color);
            }
        },

        //添加鼠标移动和左键单击显示相关信息
        handlerCesiumMouse() {
            var labelDefaultEntity = viewer.entities.add({
                label: {
                    show: false,
                    eyeOffset: new Cesium.Cartesian3(0, 0, -10),
                    showBackground: true,
                    backgroundColor: Cesium.Color.fromCssColorString("#3c4e60").withAlpha(0.2), //rgba(24, 55, 68, 0.30) rgba(30, 109, 143, 0.2)
                    fillColor: Cesium.Color.fromCssColorString("#c0fffa"),
                    font: "200 14px sans-serif",
                    horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
                    verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
                    pixelOffset: new Cesium.Cartesian2(15, 0),
                },
            });

            /*var font = "36px Microsoft YaHei";
            var labelEntity = viewer.entities.add({
                billboard: {
                    // image: textimage,  //改图片路径
                    width: 214,
                    height: 41,
                    scale: 1.0,
                    scaleByDistance: new Cesium.NearFarScalar(1000, 1.0, 1200, 0.8),
                    verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
                    horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
                    pixelOffset: new Cesium.Cartesian2(15, 0), //偏移
                    show: false,
                },
                label: {
                    // text: data.Name,
                    font: font,
                    eyeOffset: new Cesium.Cartesian3(0, 0, -10),
                    // backgroundColor:Cesium.Color.fromCssColorString("#ffffff"),
                    // style: Cesium.LabelStyle.FILL,
                    // showBackground: false,
                    fillColor: Cesium.Color.WHITE,
                    scale: 0.5,
                    scaleByDistance: new Cesium.NearFarScalar(1000, 1.0, 1200, 0.8),
                    verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
                    horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
                    // horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
                    pixelOffset: new Cesium.Cartesian2(35, -9), //偏移
                    show: false,
                },
            });*/
            let _this = this;

            var scene = viewer.scene;
            var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
            // 鼠标移入labelEntity提示框
            handler.setInputAction(function (movement) {
                var foundPosition = false;
                if (scene.mode !== Cesium.SceneMode.MORPHING) {
                    var pickedObject = scene.pick(movement.endPosition);
                    if (scene.pickPositionSupported && Cesium.defined(pickedObject) && pickedObject.id != undefined) {
                        // && pickedObject.id.id.indexOf("-pump") > -1 && pickedObject.id.type == "pump"
                        if (_this.typeIds.indexOf(pickedObject.id.type) < 0) {
                            // labelEntity.billboard.show = false;
                            // labelEntity.label.show = false;
                            labelDefaultEntity.label.show = false;
                            return;
                        }
                        var cartesian = viewer.scene.pickPosition(movement.endPosition);
                        if (Cesium.defined(cartesian)) {
                            var cartographic = Cesium.Cartographic.fromCartesian(cartesian);
                            if (_this.typeIds.indexOf(pickedObject.id.type) > -1) {
                                labelDefaultEntity.position = cartesian;
                                labelDefaultEntity.label.show = true;
                                labelDefaultEntity.label.text = pickedObject.id.name;
                                // var textimage = "";
                                // labelEntity.position = cartesian;
                                // labelEntity.billboard.show = true;
                                // labelEntity.billboard.image = textimage;
                                // labelEntity.label.show = true;
                                // labelEntity.label.text ="";
                            }
                            foundPosition = true;
                        }
                    }
                }

                if (!foundPosition) {
                    // labelEntity.billboard.show = false;
                    // labelEntity.label.show = false;
                    labelDefaultEntity.label.show = false;
                }
            }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

            _this.TooltipDiv.initTool(viewer.cesiumWidget.container);
            //左键单击
            handler.setInputAction(function (movement) {
                var pick = viewer.scene.pick(movement.position);
                if (Cesium.defined(pick) && (pick.id != undefined)) {
                    // if (pick.id._id != "" && pick.id._id != undefined && pick.id._id.length < 36) {
                    if (_this.typeIds.indexOf(pick.id.type) > -1) {
                        // var data = empdata.filter(item => item.EmployeeNo === pick.id._id)[0];
                        let imageName = "", text = "";
                        if (pick.id.name == "农业休闲观光区") {
                            imageName = "4";
                            text = "以山水资源、生态农业、特色农村为依托发展观光旅游， 果蔬采摘，农家体验游，具有集观光、休闲、度假、采摘、农产品物流、农业教育等功能。";
                        } else if (pick.id.name == "创意文化传统村落") {
                            imageName = "9";
                            text = "目前村庄民居保存较好、集中成片，具有较大的旅游开发价值。通过对传统民居区域规划改造，以传统民居为载体打造具有创意文化特色的民宿酒店，是兼具现代与传统相结合的民宿创意文化。";
                        } else if (pick.id.name == "科技农业观光区体验区") {
                            imageName = "5";
                            text = "以村庄加企业合作为契机，通过引进农业科技企业，发展生态科技农业，转变农业生产方式，提高产量，同时结合农业发展观光旅游,农民通过土地入股并参与农业生产，改善生活环境。";
                        } else if (pick.id.name == "生态农业观光区体验区") {
                            imageName = "2";
                            text = "以山水资源、生态农业、特色农村为依托发展观光旅游，农家体验游，将园区打造成为以农业科技为主导的生态休闲观光园区，具有集观光、休闲、度假等功能。";
                        } else if (pick.id.name == "生态景观区") {
                            imageName = "3";
                            text = "位于整个村域中心位置，四周田野、树林环绕，村落周边水塘星罗棋布，河流环绕村庄，远山连绵起伏，视野宽阔，自然环境优美。";
                        } else if (pick.id.name == "美丽乡村体验区") {
                            imageName = "8";
                            text = "村庄之间以村道相连，并通过林地、农田、水塘相互间隔，既相互联系又相对独立。根据用地内各村庄的现状特点，发展需求，以各自资源为依托形成各具特色的乡村旅游。";
                        } else if (pick.id.name == "集体产业用地") {
                            imageName = "1";
                            text = "以村庄加企业合作为契机，通过引进农业科技企业，发展生态科技农业，转变农业生产方式，提高产量。农民通过土地入股并参与农业生产，以提高农民收入、改善生活环境。";
                        } else if (pick.id.name == "民宿体验区") {
                            imageName = "1";
                            text = "以传统民居为载体打造具有创意文化特色的民宿酒店，是兼具现代与传统相结合的民宿创意文化，具有集观光、休闲、度假等功能。";
                        } 
                        var html = "";
                        if (imageName != "") {
                            html = "<div><div class='img'><img src='" + require("../assets/images/vim/" + imageName + ".png") + "' /></div><div class='text'><span class='title'>" + pick.id.name + "</span><br />" + text + "</div></div>";
                        } else {
                            html = "<div>名称：" + pick.id.name + "<br />地址：广西省南宁市蔡岗村" + "" + "</div>";
                        }
                        _this.TooltipDiv.showAt(movement.position, html);
                    } else {
                        _this.TooltipDiv.setVisible(false);
                    }
                } else {
                    _this.TooltipDiv.setVisible(false);
                }
            }, Cesium.ScreenSpaceEventType.LEFT_CLICK);

            handler.setInputAction(() => {
                _this.TooltipDiv.setVisible(false);
            }, Cesium.ScreenSpaceEventType.LEFT_DOWN);
        },

        TooltipDiv: (function () {

            var isInit = false;

            function _() { };

            _.initTool = function (frameDiv) {
                if (isInit) { return; }

                var div = document.createElement('DIV');
                div.className = "toolTip-left-vim";//tooltipdiv right   toolTip-left

                //var arrow = document.createElement('DIV');
                //arrow.className = "tooltipdiv-arrow";
                //div.appendChild(arrow);

                var title = document.createElement('DIV');
                title.className = "tooltipdiv-inner";
                div.appendChild(title);

                this._div = div;
                this._title = title;

                frameDiv.appendChild(div);

                isInit = true;
            }

            _.setVisible = function (visible) {
                if (!isInit) { return; }
                this._div.style.display = visible ? 'block' : 'none';
            };

            /*
            position屏幕坐标
            显示在屏幕上
            */
            _.showAt = function (position, message) {
                if (!isInit) { return; }
                if (position && message) {
                    this.setVisible(true);
                    this._title.innerHTML = message;
                    this._div.style.position = "absolute"
                    this._div.style.left = position.x + 30 + "px";
                    this._div.style.top = (position.y - this._div.clientHeight / 2) + "px";
                }
            };

            return _;
        })()
    }

    /**
     * 无人机巡检
     */
    const patrolUAV = {

        //添加图标
        addBillboard(data, type, imageurl, size, index) {
            //var width = 30, height = 38;
            var width = 32, height = 80;
            var offset = -70;
            if (size == 0) {
                width = 30;
                height = 38;
                offset = -35;
            }
            // var imageurl = data.imgurl;
            viewer.entities.add({
                // id: id,
                type: type,//自定义属性
                name: data.Name,
                show: true,
                position: Cesium.Cartesian3.fromDegrees(data.X, data.Y, data.ELEVATION),
                //orientation: new Cesium.VelocityOrientationProperty(property),
                billboard: {
                    image: imageurl,  //改图片路径
                    //eyeOffset: new Cesium.Cartesian3(0, 0, -10),
                    width: width,
                    height: height,
                    scale: 1.0,
                    scaleByDistance: new Cesium.NearFarScalar(1000, 1.0, 1200, 0.8),
                    distanceDisplayCondition: new Cesium.DistanceDisplayCondition(1.0, 200000.0),
                    verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
                    horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
                    show: true
                },
                label: {
                    text: data.bh,
                    font: "200 14px sans-serif",
                    showBackground: true,
                    backgroundColor: Cesium.Color.fromCssColorString("#3c4e60").withAlpha(0.2), //rgba(24, 55, 68, 0.30) rgba(30, 109, 143, 0.2)
                    fillColor: Cesium.Color.fromCssColorString("#c0fffa"),
                    // fillColor: Cesium.Color.BLACK,
                    verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
                    // horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
                    // horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
                    distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0, 200000.0),
                    eyeOffset: new Cesium.Cartesian3(0, 0, -10),
                    pixelOffset: new Cesium.Cartesian2(0, offset),
                    show: true
                }
            });
        },
        //转换经纬度
        transformXYZ(cartesian) {
            //将笛卡尔三维坐标转为地图坐标（弧度）
            var cartographic =
                viewer.scene.globe.ellipsoid.cartesianToCartographic(cartesian);
            //将地图坐标（弧度）转为十进制的度数
            var longitude = Cesium.Math.toDegrees(cartographic.longitude).toFixed(6);
            var latitude = Cesium.Math.toDegrees(cartographic.latitude).toFixed(6);
            var height = cartographic.height.toFixed(2); //Math.ceil
            let position = { long: longitude, lat: latitude, height: height };
            return position;
        },
        //设置位置高
        setPositionsHeight(positions, height) {
            let res = [];
            for (let i = 0; i < positions.length;) {
                // let position = this.transformXYZ(positions[i]);
                res.push([Number(positions[i]), Number(positions[i + 1]), Number(height)]);
                i = i + 2;
            }
            return res;
        },
        //添加位置高
        addPositionsHeight(data, height) {
            let res = [];
            for (let i = 0; i < data.length; i++) {
                // let position = this.transformXYZ(positions[i]);
                res.push([Number(data[i].X), Number(data[i].Y), Number(data[i].ELEVATION + height)]);
            }
            return res;
        },
        flyLine: null,
        //无人机巡检
        uavPatrol(data) {
            // let points = this.setPositionsHeight(data.positions, 500);
            let points = this.addPositionsHeight(data, 200);
            // console.log(points);
            // //飞行路线
            // this.flyLine = new mars3d.FlyLine(viewer, {
            //     name: "无人机巡检",
            //     clockRange: Cesium.ClockRange.LOOP_STOP,   //CLAMPED 到达终止时间后停止 LOOP_STOP, //到达终止时间后 循环从头播放 
            //     // interpolation: false,
            //     // clampToGround: false,
            //     // showGroundHeight: false,
            //     camera: { type: "" },
            //     speed: 600,
            //     points: points,
            //     model: {
            //         show: true,
            //         uri: "./static/ceisumModel/CesiumAir/Cesium_Air.glb", // serverURL_gltf + "/mars/wrj.glb",
            //         scale: 0.02,
            //         minimumPixelSize: 50,
            //     },
            //     path: { color: "#ffff00", width: 3, show: true, isAll: false },
            //     // onStep: function (currIndex, allCount) {
            //     //     // console.log("已漫游过点：" + currIndex, allCount);
            //     //     if (currIndex == allCount - 1) {
            //     //         viewer.entities.remove(_this.aerialEntity);
            //     //         _this.aerialEntity = null;
            //     //     }
            //     // },
            // });
            // // flyLine = new mars3d.FlyLine(viewer, flydata);

            //创建矢量数据图层
            let graphicLayer = new mars3d.layer.GraphicLayer();
            viewer.addLayer(graphicLayer);
            //飞行路线
            this.flyLine = new mars3d.graphic.RoamLine({
                name: "无人机航拍",
                speed: 600,
                positions: points,
                model: {
                    url: "./static/ceisumModel/CesiumAir/Cesium_Air.glb",
                    scale: 0.02,
                    minimumPixelSize: 50,
                    show: true,
                },
                path: {
                    color: "#ffff00",
                    width: 3,
                    isAll: false,
                    show: true,
                },
                clockRange: Cesium.ClockRange.LOOP_STOP,
                clockLoop: true, //是否循环播放
            });
            graphicLayer.addGraphic(this.flyLine);
            this.flyLine.start();
            viewer.clock.onTick.addEventListener(this.clock_onTick, this);

            //飞行转到开始点
            viewer.camera.flyTo({
                destination: Cesium.Cartesian3.fromDegrees(
                    points[0][0],
                    points[0][1],
                    20000
                ),
                duration: 2, //动画持续时间
                //飞行完毕后执行的动作
                complete: function () {
                    viewer.camera.flyTo({
                        destination: Cesium.Cartesian3.fromDegrees(
                            points[0][0],
                            points[0][1] - 0.18,
                            6000
                        ),
                        // duration: 3, //动画持续时间
                        orientation: {
                            heading: viewer.camera.heading, // 方向
                            pitch: Cesium.Math.toRadians(-15.0), // 倾斜角度
                            roll: 0.0,
                        },
                    });
                }
            });
        },
        uavEntity: null,
        frameNum: 0,
        lengthNow: 100,
        bottomRadiusNow: 100,
        clock_onTick() {
            if (!viewer.clock.shouldAnimate) return;
            this.frameNum++;
            if (this.frameNum % 1 == 0) {
                //添加地面矩形
                if (!this.uavEntity) {
                    if (this.flyLine.position) {
                        // this.flyposition = this.flyLine.position;
                        this.createCylinder();
                    }
                }
            }
            if (this.frameNum % 50 == 0) {
                let name = ["xj1", "xj2", "xj3", "xj4", "xj5", "xj6", "xj7", "xj8", "xj9", "xj10", "xj10", "xj12", "xj13", "xj14", "xj15", "xj16", "xj17", "xj18"];
                let html = "<div><img src='" + "http://119.3.43.73:8020/Video_Img/wrjxj_img/" + name[Math.floor(Math.random() * name.length)] + ".jpg" + "' /></div>";
                this.TooltipDiv0.showAt(html)
            }
        },
        //创建地面圆锥
        createCylinder() {
            // Cesium.Cartesian3.fromDegrees(114.380049685,30.644867274,Number(this.borderHeight));
            var entity = viewer.entities.add({
                position: new Cesium.CallbackProperty(() => {
                    let position = this.transformXYZ(this.flyLine.position);
                    this.lengthNow = position.height;
                    this.bottomRadiusNow = this.lengthNow * 0.3;//地面圆半径
                    return Cesium.Cartesian3.fromDegrees(position.long, position.lat, position.height / 2);
                }, false),
                cylinder: {
                    length: new Cesium.CallbackProperty(() => {
                        return this.lengthNow;
                    }, false),
                    topRadius: 0,
                    bottomRadius: new Cesium.CallbackProperty(() => {
                        return this.bottomRadiusNow;
                    }, false),
                    numberOfVerticalLines: 0,
                    material: Cesium.Color.RED.withAlpha(0.2),
                    outline: false,
                }
            });
            this.uavEntity = entity;
            // this.arrEntity.push(entity);
        },
        /**
         * 执行数据
         * @param {*} data 数据源(带wfs链接Url)
         * @param {*} jsonData 根据WFS数据获取arcgisjson数据
         */
        handleForData(data, jsonData) {
            if (data.wfsType == "点") {
                let imageurl = "", size = 0;
                if (data.data.indexOf("WRJXJD/MapServer/0") > -1) { //风险点 
                    imageurl = require("../assets/images/gxcyd.png");
                    size = 1;
                } else if (data.data.indexOf("WRJXJD/MapServer/1") > -1) {//里程桩
                    imageurl = require("../assets/images/mark1.png");
                }
                this.addBillboard(jsonData, data.id, imageurl, size);
                // } else if (data.wfsType == "线") {
                //     this.uavPatrol(jsonData);
                //     this.TooltipDiv0.initTool(viewer.cesiumWidget.container);
                //     let html = "<div><img src='http://119.3.43.73:8020/Video_Img/wrjxj_img/xj1.jpg' /></div>";
                //     this.TooltipDiv0.showAt(html);
            }
        },
        handleForDatas(data, jsonData) {
            if (data.data.indexOf("WRJXJD/MapServer/1") > -1) {//里程桩
                function compare(p) {
                    return function (a, b) {
                        let value1 = a[p];
                        let value2 = b[p];
                        return value1 - value2;
                    }
                }
                let datas = jsonData.sort(compare('num'));
                // console.log(datas, '-------');
                this.uavPatrol(datas);
                this.TooltipDiv0.initTool(viewer.cesiumWidget.container);
                let html = "<div><img src='http://119.3.43.73:8020/Video_Img/wrjxj_img/xj1.jpg' /></div>";
                this.TooltipDiv0.showAt(html);
            }
        },

        //添加鼠标移动和左键单击显示相关信息
        handlerCesiumMouse() {
            let _this = this;

            var scene = viewer.scene;
            var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);

            _this.TooltipDiv.initTool(viewer.cesiumWidget.container);
            //左键单击
            handler.setInputAction(function (movement) {
                var pick = viewer.scene.pick(movement.position);
                if (Cesium.defined(pick) && (pick.id != undefined)) {
                    // if (pick.id._id != "" && pick.id._id != undefined && pick.id._id.length < 36) {
                    if (pick.id.type.length <= 36) {
                        console.log(pick.id);
                        // var data = empdata.filter(item => item.EmployeeNo === pick.id._id)[0];
                        let html = _this.zhdhtml();
                        _this.TooltipDiv.showAt(movement.position, html);
                    } else {
                        _this.TooltipDiv.setVisible(false);
                    }
                } else {
                    _this.TooltipDiv.setVisible(false);
                }
            }, Cesium.ScreenSpaceEventType.LEFT_CLICK);

            handler.setInputAction(() => {
                _this.TooltipDiv.setVisible(false);
            }, Cesium.ScreenSpaceEventType.LEFT_DOWN);
        },
        //灾害点弹框内容html
        zhdhtml() {
            let item = {
                isShow: true,
                name: "灾害点",
                imgUrl: "http://119.3.43.73:8020/Video_Img/wrjxj_img/zhd1.jpg",
                description: "泥岩，产状为133°∠22°，陡坡下部已形成倒岩腔，坡脚有约5m³堆体积，该点与隧道口之间的坡体为水泥浆喷护。危岩体距管道约17m，对管道威胁小，现状危险性低。",
                fileList: [
                    { id: "zhd1", fileUrl: "http://119.3.43.73:8020/Video_Img/wrjxj_img/zhd1.jpg" },
                    { id: "zhd2", fileUrl: "http://119.3.43.73:8020/Video_Img/wrjxj_img/zhd2.jpg" },
                    { id: "zhd3", fileUrl: "http://119.3.43.73:8020/Video_Img/wrjxj_img/zhd3.jpg" },
                ]
            }
            let index = 0;
            // <div class="titletext">'+ item.name + '</div>\
            var html = '<div class="content">\
                <div class="default">\
                    <img src="'+ item.imgUrl + '" />\
                </div>\
                <div class="active">\
                    <img id="imgUrl" src="'+ item.fileList[index].fileUrl + '" />\
                    <div class="details">'+ item.description + '</div>\
                    <div class="prev" id="prev"></div>\
                    <div class="next" id="next" ></div>\
                </div>\
            </div>\
            </div>';
            setTimeout(() => {
                document.getElementById("prev").onclick = function myclick() {
                    if (index > 0) {
                        index--;
                    } else if (index == 0) {
                        index = item.fileList.length - 1;
                    }
                    document.getElementById("imgUrl").src = item.fileList[index].fileUrl;
                }
                document.getElementById("next").onclick = function myclick() {
                    if (index < item.fileList.length - 1) {
                        index++;
                    } else if (index == item.fileList.length - 1) {
                        index = 0;
                    }
                    document.getElementById("imgUrl").src = item.fileList[index].fileUrl;
                }
            }, 1000);

            return html;
        },
        TooltipDiv: (function () {

            var isInit = false;

            function _() { };

            _.initTool = function (frameDiv) {
                if (isInit) { return; }

                var div = document.createElement('DIV');
                div.className = "toolTip-left-uav";//tooltipdiv right   toolTip-left

                //var arrow = document.createElement('DIV');
                //arrow.className = "tooltipdiv-arrow";
                //div.appendChild(arrow);

                var title = document.createElement('DIV');
                title.className = "tooltipdiv-inner";
                div.appendChild(title);

                this._div = div;
                this._title = title;

                frameDiv.appendChild(div);

                isInit = true;
            }

            _.setVisible = function (visible) {
                if (!isInit) { return; }
                this._div.style.display = visible ? 'block' : 'none';
            };

            /*
            position屏幕坐标
            显示在屏幕上
            */
            _.showAt = function (position, message) {
                if (!isInit) { return; }
                if (position && message) {
                    this.setVisible(true);
                    this._title.innerHTML = message;
                    this._div.style.position = "absolute"
                    this._div.style.left = position.x + 30 + "px";
                    this._div.style.top = (position.y - this._div.clientHeight) + "px";
                    // this._div.style.top = (position.y - this._div.clientHeight / 2) + "px";
                }
            };

            return _;
        })(),
        TooltipDiv0: (function () {

            var isInit = false;

            function _() { };

            _.initTool = function (frameDiv) {
                if (isInit) { return; }

                var div = document.createElement('DIV');
                div.className = "toolTip-left-uav";//tooltipdiv right   toolTip-left

                //var arrow = document.createElement('DIV');
                //arrow.className = "tooltipdiv-arrow";
                //div.appendChild(arrow);

                var title = document.createElement('DIV');
                title.className = "tooltipdiv-inner";
                div.appendChild(title);

                this._div = div;
                this._title = title;

                frameDiv.appendChild(div);

                isInit = true;
            }

            _.setVisible = function (visible) {
                if (!isInit) { return; }
                this._div.style.display = visible ? 'block' : 'none';
            };

            /*
            position屏幕坐标
            显示在屏幕上
            */
            _.showAt = function (message) {
                if (!isInit) { return; }
                if (message) {
                    this.setVisible(true);
                    this._title.innerHTML = message;
                    this._div.style.position = "absolute"
                    this._div.style.right = "20px";
                    this._div.style.bottom = "100px";
                    // this._div.style.left = position.x + 30 + "px";
                    // this._div.style.top = (position.y - this._div.clientHeight / 2) + "px";
                }
            };

            return _;
        })(),

    }

    /**
     * 山体滑坡
     */
    const sthp = {
        addBillboardPump(data, firstStart) {
            var width = 65, height = 98;
            var font = "36px Microsoft YaHei";
            var imageurl = "", textimage = "";
            if (data.BZLX === "压力监控") {
                imageurl = "./static/images/yali.png";
                textimage = "./static/images/yali_back.png";
            } else if (data.BZLX === "摄像头") {
                imageurl = "./static/images/shipin.png";
                textimage = "./static/images/shipin_back.png";
            }
            else if (data.BZLX === "水量监控") {
                imageurl = "./static/images/shuiliang.png";
                textimage = "./static/images/shuiliang_back.png";
            }
            var citizensBankPark = viewer.entities.add({
                id: firstStart + 1,
                type: 'pump',//自定义属性
                name: data.Name,
                bzlx: data.BZLX,
                position: Cesium.Cartesian3.fromDegrees(data.X, data.Y, data.Z),
                //orientation: new Cesium.VelocityOrientationProperty(property),
                billboard: {
                    image: imageurl,  //改图片路径
                    //eyeOffset: new Cesium.Cartesian3(0, 0, -10),
                    width: width,
                    height: height,
                    scale: 1.0,
                    scaleByDistance: new Cesium.NearFarScalar(1000, 1.0, 1200, 0.8),
                    distanceDisplayCondition: new Cesium.DistanceDisplayCondition(1.0, 10000.0),
                    verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
                    horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
                    show: true
                }
            });
            /*特殊处理，定位到标注*/
            /* viewer.trackedEntity = citizensBankPark;
            viewer.zoomTo(viewer.entities); */
        },
        showAt(datas) {
            let vedioIp = ipConfig.ip + ipConfig.threePort;
            var scene = viewer.scene;
            var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
            handler.setInputAction(function (movement) {
                var pick = viewer.scene.pick(movement.position);
                if (Cesium.defined(pick) && (pick.id != undefined)) {
                    let data;//datas.filter(item => item.Id === pick.id._id)[0];
                    for (var i = 0; i < datas.length; i++) {
                        if (i === (pick.id._id - 1)) {
                            data = datas[i];
                        }
                    }
                    //水量监控水量，压力监控
                    if (pick.id._id != "" && pick.id._id != undefined && pick.id._id > 6) {
                        TooltipDiv.initTool(viewer.cesiumWidget.container);
                        var status = "正常";
                        if (pick.id._id === 14 || pick.id._id === 15 || pick.id._id === 19) {
                            status = "异常";
                        }
                        var html = "<div>名称：" + data.Name + "<br />类型：" + data.BZLX + "<br />状态：" + status
                            + "<br />时间：2021-06-21</div>";
                        TooltipDiv.showAt(movement.position, html);
                    }
                    //视频监控
                    else {
                        let videoElement = document.getElementById("trailer");
                        videoElement.style.display = "block";
                        videoElement.style.width = "250px";
                        videoElement.style.height = "200px";
                        videoElement.style.right = "20px";
                        videoElement.style.bottom = "20px";
                        videoElement.style.position = "absolute";

                        var videoUrl = "";//"http://119.3.43.73:8027/imgs/video/20210716_105010.mp4";
                        switch (pick.id._id) {
                            case 1:
                                videoUrl = vedioIp + "/Video_Img/senlinjiankong.mp4";
                                break;
                            case 2:
                                videoUrl = vedioIp + "/Video_Img/2.mp4";
                                break;
                            case 3:
                                videoUrl = vedioIp + "/Video_Img/3.mp4";
                                break;
                            case 4:
                                videoUrl = vedioIp + "/Video_Img/4.mp4";
                                break;
                            case 5:
                                videoUrl = vedioIp + "/Video_Img/5.mp4";
                                break;
                            case 6:
                                videoUrl = vedioIp + "/Video_Img/6.mp4";
                                break;
                            default:
                        }
                        videoElement.src = videoUrl;
                        videoElement.play();
                    }

                }
                else {
                    TooltipDiv.setVisible(false);
                    let videoElement = document.getElementById("trailer");
                    videoElement.style.display = "none";
                }
            }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
        },
        twinklePoint(point) {
            var entity = viewer.entities.add({
                point: {
                    //show: pointShow,
                    pixelSize: 16,
                    color: new Cesium.CallbackProperty(function color() {//关键代码
                        return Cesium.Color.fromRandom({
                            minimumRed: 0.15,
                            minimumGreen: 0.35,
                            minimumBlue: 0.45,
                            alpha: 1.0
                        });
                    }, false),
                    //heightReference: 25000,
                    distanceDisplayCondition: new Cesium.DistanceDisplayCondition(1.0, 10000.0)
                },
                position: Cesium.Cartesian3.fromDegrees(Number(point.X), Number(point.Y), Number(point.Z)),//经纬度
                label: {//可以在点得旁边显示字
                    //text: text,
                    scale: 0.8,
                    fillColor: Cesium.Color.YELLOW,
                    //heightReference: 25000,
                    verticalOrigin: Cesium.VerticalOrigin.LEFT,
                    horizontalOrigin: Cesium.HorizontalOrigin.CENTER
                    //pixelOffset: new Cesium.Cartesian2(10, 20)
                },
                show: true
            });
        },
        /* 鼠标滑过获取用户信息 */
        mousemove() {

            var font = "36px Microsoft YaHei";
            var labelEntity = viewer.entities.add({
                billboard: {
                    // image: textimage,  //改图片路径
                    width: 214,
                    height: 41,
                    scale: 1.0,
                    scaleByDistance: new Cesium.NearFarScalar(1000, 1.0, 1200, 0.8),
                    verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
                    horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
                    pixelOffset: new Cesium.Cartesian2(15, 0),            //偏移
                    show: false
                },
                label: {
                    // text: data.Name,
                    font: font,
                    eyeOffset: new Cesium.Cartesian3(0, 0, -10),
                    // backgroundColor:Cesium.Color.fromCssColorString("#ffffff"),
                    // style: Cesium.LabelStyle.FILL,
                    // showBackground: false,
                    fillColor: Cesium.Color.WHITE,
                    scale: 0.5,
                    scaleByDistance: new Cesium.NearFarScalar(1000, 1.0, 1200, 0.8),
                    verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
                    horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
                    // horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
                    pixelOffset: new Cesium.Cartesian2(35, -9),//偏移
                    show: false
                }
            });

            var scene = viewer.scene;
            var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
            // 鼠标移入labelEntity提示框
            handler.setInputAction(function (movement) {

                var foundPosition = false;

                if (scene.mode !== Cesium.SceneMode.MORPHING) {
                    var pickedObject = scene.pick(movement.endPosition);
                    if (scene.pickPositionSupported && Cesium.defined(pickedObject) && pickedObject.id != undefined) {// && pickedObject.id.id.indexOf("-pump") > -1 && pickedObject.id.type == "pump"
                        if (pickedObject.id.type != "pump") {
                            labelEntity.billboard.show = false;
                            labelEntity.label.show = false;
                            return;
                        }
                        var cartesian = viewer.scene.pickPosition(movement.endPosition);
                        if (Cesium.defined(cartesian)) {
                            var cartographic = Cesium.Cartographic.fromCartesian(cartesian);
                            labelEntity.position = cartesian;
                            var textimage = "";
                            if (pickedObject.id.bzlx === "压力监控") {
                                textimage = "./static/images/yali_back.png";
                            } else if (pickedObject.id.bzlx === "摄像头") {
                                textimage = "./static/images/shipin_back.png";
                            }
                            else if (pickedObject.id.bzlx === "水量监控") {
                                textimage = "./static/images/shuiliang_back.png";
                            }
                            labelEntity.billboard.show = true;
                            labelEntity.billboard.image = textimage;
                            labelEntity.label.show = true;
                            labelEntity.label.text = pickedObject.id.name === "" ? '类型: ' + pickedObject.id.bzlx : pickedObject.id.name;
                            // labelEntity.label.eyeOffset = new Cesium.Cartesian3(0.0, 0.0, -cartographic.height * (scene.mode === Cesium.SceneMode.SCENE2D ? 1.5 : 1.0));
                            // labelEntity.label.eyeOffset = new Cesium.Cartesian3(0.0, 0.0, -10);


                            foundPosition = true;
                        }
                    }
                }

                if (!foundPosition) {
                    labelEntity.billboard.show = false;
                    labelEntity.label.show = false;
                }
            }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);


        }
    }

    return {
        handleForPipe: function (data) {
            handleForWFS(data, "pipe");
        },
        handleForVIM: function (data) {
            handleForWFS(data, "vim");
            vim.handlerCesiumMouse();
            let datas = {
                offsetHeight: 0,
                offsetEast: 0,
                offsetNorth: 0,
                name: "vim",
                url: "http://119.3.43.73:8020/gx_zjc_1/tileset.json",
            };
            vim.load3DTiles(datas);
        },
        handleForUAVpatrol: function (data) {
            handleForWFS(data, "patrolUAV");
            patrolUAV.handlerCesiumMouse();
        },
        handleForSTHP: function (data) {
            handleForSTHPData(data, "sthp");
            sthp.mousemove();
        }
    };
})();

// Export function, used in npm
export default DataManagerScene;


